/**
 * 
 */
package edu.ucr.cs.dblab.acestore.base.datatypes;

import java.nio.ByteBuffer;

/**
 * @author jarodwen
 * @created Jan 18, 2011
 */
public class TupleBuilder {

	public static byte[] BUILDTUPLE(byte[][] data){
		int capacity = Short.SIZE / 8;
		for(int i = 0; i < data.length; i++){
			capacity += Short.SIZE / 8 + data[i].length;
		}
		byte[] output = new byte[capacity];
		ByteBuffer buf = ByteBuffer.wrap(output);
		buf.putShort((short)(data.length));
		int offset = 0;
		for(int i = 0; i < data.length; i++){
			buf.putShort(Short.SIZE / 8 * (i + 1), (short)(data[i].length));
			buf.position(Short.SIZE / 8 * (data.length + 1) + offset);
			buf.put(data[i], 0, data[i].length);
			offset += data[i].length;
		}
		return output;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
